package com.itheima.controller;

import com.itheima.pojo.Dept;
import com.itheima.pojo.Result;
import com.itheima.service.DeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/depts")
public class DeptController {

    @Autowired
    @Qualifier("deptServiceImpl")
    private DeptService deptService;

    /**
     * 查询所有部门信息
     * @return
     */
    @GetMapping
    public Result DeptList(){
        List<Dept> depts = deptService.DeptList();
        return Result.success(depts);
    }

    /**
     * 删除部门信息
     * @param id
     * @return
     */
    @DeleteMapping
    public Result DeptDelete(Integer id){
        deptService.DpetDelete(id);
        return Result.success();
    }

    /**
     * 添加部门信息
     * @param dept
     * @return
     */
    @PostMapping
    public Result DeptAdd(@RequestBody Dept dept){
        deptService.DeptAdd(dept);
        return Result.success();
    }

    /**
     * 根据id查询部门信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result DeptFindById(@PathVariable Integer id){
        Dept dept = deptService.DeptFindById(id);
        return Result.success(dept);
    }

    /**
     * 修改部门信息
     * @param dept
     * @return
     */
    @PutMapping
    public Result DeptUpdate(@RequestBody Dept dept){
        deptService.DeptUpdate(dept);
        return Result.success();
    }

}
